#include "test.h"
#include "shared.h"
#include "serial.h"
#include "HD61202.h"
#include "strings.h"
#include "event.h"
#include "util.h"
#include "timers.h"

void sendInt(unsigned int toSend, unsigned const rom char * text, unsigned char *buffer){
	convertInt2ASCII(toSend, buffer);
	putrsUSARTInt(text);
	putrsUSARTInt(": 0x");
	putsUSARTInt(buffer);
	CRLF();
}

/*
test LCD functions and do some timing
use timer0 in 256x prescale mode, resulting in a precision of 25.6 uS
*/
void testMode(){
	char sec;
	unsigned char tmpChar[5];
	unsigned int tOff, tInit, tClear, tGoto, tFill, tString;
	
	WriteTimer0(0);
	T0CONbits.TMR0ON = 1;
	GLCD_Shutdown();
	T0CONbits.TMR0ON = 0;
	tOff = ReadTimer0();
	
	WriteTimer0(0);
	T0CONbits.TMR0ON = 1;
	GLCD_Initialize();
	T0CONbits.TMR0ON = 0;
	tInit = ReadTimer0();
	
	WriteTimer0(0);
	T0CONbits.TMR0ON = 1;
	GLCD_ClearScreen();
	T0CONbits.TMR0ON = 0;
	tClear = ReadTimer0();
	
	WriteTimer0(0);
	T0CONbits.TMR0ON = 1;
	GLCD_GoTo(0,0);
	T0CONbits.TMR0ON = 0;
	tGoto = ReadTimer0();
	
	WriteTimer0(0);
	T0CONbits.TMR0ON = 1;
	GLCD_WriteString(testString);
	T0CONbits.TMR0ON = 0;
	tString = ReadTimer0();
	
	// writing off the edge of the LCD causes problems.
	//GLCD_WriteStringROM(welcomeString);
	GLCD_GoTo(1,1);
	GLCD_WriteString(testString);
	putsUSARTInt(testString);
	CRLF();
	sec = secTick;
	while(sec == secTick);
	while(sec != secTick);
	
	WriteTimer0(0);
	T0CONbits.TMR0ON = 1;
	GLCD_FillScreen();
	T0CONbits.TMR0ON = 0;
	tFill = ReadTimer0();
	
	// convert data to ascii, send to host
	tmpChar[4] = 0;
	
	sendInt(tOff, "tOff", tmpChar);
	sendInt(tInit, "tInit", tmpChar);
	sendInt(tClear, "tClear", tmpChar);
	sendInt(tGoto, "tGoto", tmpChar);
	sendInt(tFill, "tFill", tmpChar);
	sendInt(tString, "tString", tmpChar);
	
	while(sec == secTick);
	while(sec != secTick);
	
	
}	

